using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Random = UnityEngine.Random;

public class IngredientsMove : MonoBehaviour
{
    [SerializeField] private int type;

    private Color myColor;

    private Rigidbody2D thisRg;

    private Manager mn;
    // Start is called before the first frame update
    void Start()
    {
        thisRg = this.GetComponent<Rigidbody2D>();
        mn = GameObject.Find("Start").GetComponent<Manager>();
    }

    private void Awake()
    {
        if (Random.Range(0f, 1f) > 0.3f)
        {
            type = 0;
            myColor = new Color(1f, Random.Range(0f,0.4f), 0f);
        }
        else
        {
            type = 1;
            myColor = new Color(0f, 255 - Random.Range(0f, 180f), 255 - Random.Range(0f, 180f));
        }

        this.GetComponent<SpriteRenderer>().color = myColor;
    }

    // Update is called once per frame
    void Update()
    {
        //thisRg.AddForce(Vector2.right*0.5f*Time.deltaTime,ForceMode2D.Impulse);
        this.gameObject.transform.Translate(Vector2.right*1.5f*Time.deltaTime);
    }

    private void OnCollisionEnter2D(Collision2D col)
    {
        if (col.gameObject.tag == "Pot"&& type == 1)
        {
            mn.LifeChange(-1);
            Destroy(this.gameObject);
        }
        else if (col.gameObject.tag == "Pot")
        {
            Destroy(this.gameObject);
        }
    }

    private void OnTriggerEnter2D(Collider2D col)
    {
        if (col.gameObject.name == "MouseClickManager" && this.type == 1)
        {
            Destroy(this.gameObject);
        }
    }
}
